package com.juzipi.demo.inversion.improve;

/**
 * 依赖倒转
 */

public class DependencyInversion {

    public static void main(String[] args) {
        //客户端无需改变
        Person person = new Person();
        Email email = new Email();
        person.receive(email);

        person.receive(new Weixin());

    }
}
//定义一个接口
interface IReceiver{
    public String getInfo();
}

class Email implements IReceiver {
    public String getInfo(){
        return "信息：hello world";
    }
}

//增加weixin
class Weixin implements IReceiver{

    @Override
    public String getInfo() {
        return "hello 微信";
    }
}

class Person{
    //这里是我们对接口的依赖
    public void receive(IReceiver receiver){
        System.out.println(receiver.getInfo());

    }
}